<%@ Page Language="C#" MasterPageFile="~/PublicEnquiries.Master" AutoEventWireup="true" EnableViewState="true" CodeBehind="Search.aspx.cs" Inherits="Tribal.EYO.PublicEnquiry.Search" %>
<%@ MasterType VirtualPath="~/PublicEnquiries.master" %>
<%@ Register TagPrefix="eyo" Namespace="Tribal.EYO.WebUI.CustomControls" Assembly="Tribal.EYO.WebUI.CustomControls" %> 

<asp:Content ID="SearchPageToolbar" ContentPlaceHolderID="toolbarContentPlaceHolder" runat="server">

    <div id="searchpageToolbarDiv" runat="server" class="toolbar_container"> </div>
    
    <div id="ManageBasketLink" class="manage_basket_container">
        <a id="A1" class="BasketScriptWarn" runat="server"><%= this.scriptWarnText%></a>
    </div>
    <div id="searchFeedbackForm" class="feedback_form_link" runat="server"></div>
    
</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
   
    <script type="text/javascript">
    /*<![CDATA[*/
    
    /* The function extracts the provider id from the control id */
    /* WI 51911 - Add Distance to results - Rename function from GetProviderID */
    /* SBI 52689 MC 07/11 - note the id is of the form provider_cb_<name>|<ID>|<postcode>|<distance>*/
    function GetCheckboxID(cbIDStr)
    {
        var sID = "";
        var sIDStr = "|";
        
        var sCbIDStr = new String(cbIDStr);
        var iPos = sCbIDStr.indexOf(sIDStr);
        if(iPos != -1)
            sID = sCbIDStr.substring(iPos + sIDStr.length);
        
        return sID;
    }
    
    /* Add the selected providers to the shopping basket */    
    function AddProvidersToBasket()
    {
        document.getElementById('itemsAddedId').innerText = "";
        
        // Couldn't find another way to get a handle on the checkboxes on the screen, so...
        // Get a list of all the inputs
        var cb = document.getElementsByTagName("input");
        
        var sIDS = "";
        var iCBS = 0;
        var iCBSChecked = 0;
        for(var j=0; j < cb.length; j++)
        {
            // Look for a checkbox
            if(cb[j].type == "checkbox")
            {
                iCBS++;
                
                if(cb[j].checked)
                {
                    // Extract the provider id from the control
                    var sID = GetCheckboxID(cb[j].id);
                    iCBSChecked++;
                    
                    if(sIDS != "")
                        sIDS += ",";
                    sIDS += sID;
                }
            }
        }

        /* WI 42286 - Add Comparison Link - Renamed from SaveToShopping Basket to SaveCSVToCookie */
        if (SaveCSVToCookie("PESearchCookie", sIDS) == true)
        {
            document.getElementById('itemsAddedId').innerText = "<%=itemsAddedToBasketText%>";
            
            // JW 03/06/08 (15476) - if not IE then send an alert instead
            if (navigator.userAgent.indexOf('MSIE') == -1)
            {
                alert('<%=itemsAddedToBasketText%>');
            }
            
        }
        
        return;
    }
    
    /* Add the current provider to the shopping basket */
    function AddProviderToBasket()
    {   
        document.getElementById('itemAddedId').innerText = "";
        
        var obj = document.getElementById("ctl00_ContentPlaceHolder1_hiddenCheckboxID");
        if(obj != null)
        {   
            if(obj.length != 0)
            {
                var sId = obj.getAttribute("value");
                /* WI 42286 - Add Comparison Link - Renamed from SaveToShopping Basket to SaveCSVToCookie */
                if (SaveCSVToCookie("PESearchCookie", sId) == true)
                {
                    document.getElementById('itemAddedId').innerText = "<%=itemAddedToBasketText%>";
                    
                    // JW 03/06/08 (15476) - if not IE then send an alert instead
                    if (navigator.userAgent.indexOf('MSIE') == -1)
                    {
                        alert('<%=itemAddedToBasketText%>');
                    }
                }   
            }
        }
        return;
    }
    
    /* Return from the shopping basket, back to the calling page */
    function ReturnToResults()
    {
        var obj = document.getElementById("ctl00_ContentPlaceHolder1_hiddenPageHistory");
        if(obj != null)
        {
            if(obj.length != 0)
            { 
                var iPages = obj.getAttribute("value");
                // JW 03/06/08 (15476) - argh! firefox does not error or give any warnings but unless you make the variable numeric it won't work!!!
                window.history.go(iPages * 1);
            }
        }
    }

    /* WI 42286 - Add Comparison Link - Get the id's of the selected providers.
       Ensuring that at least 2 have been selected, but a maximum of only 3. */
    function GetProviders()
    {
        // Was gonna add the checking of the Ids into a function, but realised I needed, the count also
        // so sadly this is copied from AddProvidersToBasket
        // Couldn't find another way to get a handle on the checkboxes on the screen, so...
        // Get a list of all the inputs
        var cb = document.getElementsByTagName("input");

        var sIDS = "";
        var iCBS = 0;
        var iCBSChecked = 0;
        for (var j = 0; j < cb.length; j++)
        {
            // Look for a checkbox
            if (cb[j].type == "checkbox")
            {
                iCBS++;

                if (cb[j].checked)
                {
                    // Extract the provider id from the control
                    var sID = GetCheckboxID(cb[j].id);
                    iCBSChecked++;

                    if (sIDS != "")
                        sIDS += ",";
                    sIDS += sID;
                }
            }
        }

        // Clear the error message and hide it
        document.getElementById('<%= sbErrorMessage.ClientID %>').innerHTML = "";
        document.getElementById('<%= sbErrorMessage.ClientID %>').style.display = 'none';

        if (iCBSChecked == 0)
        {
            document.getElementById('<%= sbErrorMessage.ClientID %>').innerHTML = '<%=this.sNoProvidersToCompareErr %>';
            document.getElementById('<%= sbErrorMessage.ClientID %>').style.display = '';
            return false;
        }
        else if (iCBSChecked < 2)
        {
            document.getElementById('<%= sbErrorMessage.ClientID %>').innerHTML = '<%=this.sMinProvidersToCompareErr %>';
            document.getElementById('<%= sbErrorMessage.ClientID %>').style.display = '';
            return false;
        }
        else if (iCBSChecked > 3)
        {
            document.getElementById('<%= sbErrorMessage.ClientID %>').innerHTML = '<%=this.sMaxProvidersToCompareErr %>';
            document.getElementById('<%= sbErrorMessage.ClientID %>').style.display = '';
            return false;
        }

        SaveCompareCookie(sIDS);

        return true;
    }
        
    /*]]>*/
    </script>
    
    <div runat="server" id="SearchContent" visible="false">
        
        <asp:Label ID="info_messages" CssClass="info_messages" runat="server"></asp:Label>
        <asp:Label ID="error_messages" CssClass="error_messages" runat="server"></asp:Label>
        
        <asp:Wizard ID="Wizard1" runat="server" NavigationButtonStyle-CssClass="search_wizard_buttons" DisplayCancelButton="true" OnCancelButtonClick="DoNewSearch" OnFinishButtonClick="DoFinish" OnNextButtonClick="DoNext" OnPreviousButtonClick="DoPrev">
            <WizardSteps>
                <asp:WizardStep ID="WizardStepInitial" Title="Start" runat="server">
                </asp:WizardStep>
            </WizardSteps>
        </asp:Wizard>
        
    </div>
     
    <div runat="server" id="ResultsContent" visible="false">
        
        <div class="your_results_container">
            <h2 id="yourResultsHeader" class="your_results_header" runat="server"></h2>
        </div>

        <!-- WI 49430 - Sorting -->
        <div id="DivForSortLabelScriptWarn">
            <asp:Label ID="SortLabelScriptWarn" class="UserSortScriptWarn" runat="server">Script not enabled. Ascending/Descending Option is not used for Default Sort</asp:Label>
        </div>

        <!-- WI 48864 - Sorting -->
        <div id="DivForTopUserOrder" class="top_user_order_results" style='display:none;' runat="server">
            
            <asp:Label ID="TopSortLabel" runat="server">Sort:</asp:Label> <asp:DropDownList ID="TopUserOrderDDL" CssClass="dropDownList" runat="server"></asp:DropDownList>
            <asp:DropDownList ID="TopUserAscDescOrderDDL" CssClass="dropDownList" runat="server"></asp:DropDownList>
            <asp:Button ID="TopUserSortGo" OnClick="DoSort" CssClass="top_sort_go_button" runat="server" />           
        </div>
        
        <div id="divForResultsGrid" class="grid_container" runat="server">
            
            <div class="top_paging_container" runat="server" id="topPagingContainer">
                <div id="DivForTopPagingControls" class="paging_container" runat="server"></div>
            </div>
            
            <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CssClass="results_grid">
                <Columns>
                </Columns>
            </asp:GridView>
            
            <div id="addToBasketLink" class="add_to_basket_link_container"></div>
            
            
        </div>

        <!-- WI 48864 - Sorting -->
        <div id="DivForBottomUserOrder" class="bottom_user_order_results" style='display:none;' runat="server">
            <asp:Label ID="BottomSortLabel" runat="server">Sort:</asp:Label> <asp:DropDownList ID="BottomUserOrderDDL" CssClass="dropdownList" runat="server"></asp:DropDownList>
            <asp:DropDownList ID="BottomUserAscDescOrderDDL" CssClass="dropDownList" runat="server"></asp:DropDownList>
            <asp:Button ID="BottomUserSortGo" OnClick="DoSort" CssClass="bottom_sort_go_button" runat="server" />

            <div><p>&nbsp;</p></div>
        </div>

        <script type="text/javascript">
        /*<![CDATA[*/
        // WI 49340 -   Javascript Not enabled
        if (document.getElementById)
        {
            // Scripting is available, so hide the warning message
            document.getElementById('DivForSortLabelScriptWarn').innerHTML = '';
            document.getElementById('DivForSortLabelScriptWarn').style.display = 'none';

            // The user sort controls are initially configured as the neither showing

            // If the Top Sort has been rendered/shown server side, so we don't need to worry here,
            // but...
            // If the Bottom Sort has been configured to display - show it
            // as this may not have been shown server side yet
            //
            // WI 52949 - Need to check exisitance of the elements, if no results
            //            are returned the elements aren't on the page
            if(<%=nShowUserSortBottom %> == 1)
                if(document.getElementById('<%= DivForBottomUserOrder.ClientID %>'))
                    document.getElementById('<%= DivForBottomUserOrder.ClientID %>').style.display = '';

            if(document.getElementById('<%= TopUserOrderDDL.ClientID %>'))
                if(document.getElementById('<%= TopUserOrderDDL.ClientID %>').selectedIndex != -1)
                    EnableDisableAscDesc(document.getElementById('<%= TopUserOrderDDL.ClientID %>'));
        }

        function EnableDisableAscDesc(ddlObject)
        {
            // If the "default" has been selected - disable the ascending/descending
            // Don't worry about whether we are showing top or bottom, the control
            // exists so won't error
            if(ddlObject[ddlObject.selectedIndex].value == -1)
            {
                document.getElementById('<%= TopUserAscDescOrderDDL.ClientID %>').disabled = true;
                document.getElementById('<%= BottomUserAscDescOrderDDL.ClientID %>').disabled = true;
            }
            else
            {
                document.getElementById('<%= TopUserAscDescOrderDDL.ClientID %>').disabled = false;
                document.getElementById('<%= BottomUserAscDescOrderDDL.ClientID %>').disabled = false;
            }
        }

        function UserOrderByChanged(ddlObject)
        {
            if(ddlObject.id == '<%= TopUserOrderDDL.ClientID %>')
            {
                // If we are displaying the bottom control - set it accordingly
                if(<%=nShowUserSortBottom %> == 1)
                    document.getElementById('<%= BottomUserOrderDDL.ClientID %>').selectedIndex = document.getElementById('<%= TopUserOrderDDL.ClientID %>').selectedIndex;                
            }
            else if(ddlObject.id == '<%= BottomUserOrderDDL.ClientID %>')
            {
                // If we are displaying the top control - set it accordingly
                if(<%=nShowUserSortTop %> == 1)
                    document.getElementById('<%= TopUserOrderDDL.ClientID %>').selectedIndex = document.getElementById('<%= BottomUserOrderDDL.ClientID %>').selectedIndex;
            }

            EnableDisableAscDesc(ddlObject);
        }

        function UserOrderByAscDescChanged(ddlObject)
        {
            if(ddlObject.id == '<%= TopUserAscDescOrderDDL.ClientID %>')
            {
                // If we are displaying the bottom control - set it accordingly
                if(<%=nShowUserSortBottom %> == 1)
                    document.getElementById('<%= BottomUserAscDescOrderDDL.ClientID %>').selectedIndex = document.getElementById('<%= TopUserAscDescOrderDDL.ClientID %>').selectedIndex;
            }
            else if(ddlObject.id == '<%= BottomUserAscDescOrderDDL.ClientID %>')
            {
                // If we are displaying the top control - set it accordingly
                if(<%=nShowUserSortTop %> == 1)
                    document.getElementById('<%= TopUserAscDescOrderDDL.ClientID %>').selectedIndex = document.getElementById('<%= BottomUserAscDescOrderDDL.ClientID %>').selectedIndex;
            }
        }
        /*]]>*/
        </script>
        
        <div class="bottom_paging_container" runat="server" id="bottomPagingContainer">
            <div id="DivForBottomPagingControls" runat="server" class="paging_container"></div>
        </div>
        
        
        <div id="backToRegResultsDiv2" class="back_to_reg_results2">Please use your browsers back button to return to your main results list.</div>
        <div id="resultsButtonDiv">
            <asp:Button ID="NewSearchButton" OnClick="DoNewSearch" Text="New Search" CssClass="new_search_button" runat="server"/>
        </div>
        
        <script type="text/javascript">
        /*<![CDATA[*/
        if (document.getElementById)
        {
            // WI 33513 - Registration Type  
            // Are we displaying the registration or provider list
            if(<%=searchMode %> != 2)
            {
                // We are in 'normal' provider search mode OR registration search mode, so
                // hide the "Back to Reg Results"
                document.getElementById('backToRegResultsDiv2').innerHTML = '';
                document.getElementById('backToRegResultsDiv2').style.display = 'none'; 
            }
            else
            {
                // We are displaying a list of providers, but from the registration screen
                // so we need to add the additional Back button
                document.getElementById('backToRegResultsDiv2').innerHTML 
                    = '<ul><li><input type="button" value="<%=this.backToResultsText %>" onclick="javascript:history.back(); return false;" /></li><li>' 
                        + document.getElementById('resultsButtonDiv').innerHTML + '</li></ul>';
                
                document.getElementById('resultsButtonDiv').innerHTML = '';
                document.getElementById('resultsButtonDiv').style.display = 'none';
            }
            
            // WI 33512 - Registration Type - End
            
             // WI 33512 - Add registration search - Only display Manage basket and Add To Basket link if
             //            we are on the providers list
            if(<%=nCookiesEnabled %> == 1 && <%=searchMode %> != 1)
            {
                document.getElementById('ManageBasketLink').innerHTML = '<div class="results_basket_link">'
                                                                      + '<a href = "Search.aspx?shoppingBasket=1" class="manage_To_Basket_Link">'
                                                                      + '<%=this.manageBasketText %>'
                                                                      + '</a></div>';
                
                if (document.getElementById('addToBasketLink') != null)
                {
                    var sHTML = '<button class="add_To_Basket_Link" onclick="AddProvidersToBasket();return false;">';
                    sHTML = sHTML + "<%=this.addToBasketText %>";
                    sHTML = sHTML + '</button>';
                    sHTML = sHTML + '&nbsp;&nbsp;&nbsp;<label class="items_added_to_basket" id="itemsAddedId" />';
                    document.getElementById('addToBasketLink').innerHTML = sHTML;
                }
            }
            else if(<%=searchMode %> == 0)
            {
                // Cookies aren't enabled
                document.getElementById('ManageBasketLink').innerHTML = '<a class="BasketCookieWarn"><%= this.cookieWarnText%></a>';
            }
            else
            {
                // Must be on the registration list - hide the manage basket/cookie warning
                document.getElementById('ManageBasketLink').innerHTML = '';
                document.getElementById('ManageBasketLink').style.display = 'none';
            }
        }
        /*]]>*/
        </script>
    </div>
    
    <div runat="server" id="ProviderContent" visible="false">

      
        
        <h2 id="providerInformationHeader" class="provider_information_header" runat="server" >Provider Information:</h2>
         
        
        
        <div runat="server" id="printLinkDiv" class="provider_details_print_link"></div>
        
        <div>
            <!-- WI 51911 - Add Provider Distance to Results - Rename hidden field from hiddenProviderID -->
            <input id="hiddenCheckboxID" type="hidden"  runat="server"/>
        </div>

        <img alt="Provider Logo" runat="server" visible="false" id="imgProviderLogo" class="provider_logo" />
        
        <div id="provider_name" runat="server"></div>
        
        <table class="provider_info_table">
            <tr>
                <td id="column1" class="column1" runat="server"></td>
                <td id="column2" class="column2" runat="server"></td>
                <td id="column3" class="column3" runat="server"></td>
            </tr>
        </table>
        
        <div id="backToRegResultsDiv" class="back_to_reg_results">Please use your browsers back button to return to your main results list.</div>
        <div id="backToResultsDiv" class="back_to_results">Please use your browsers back button to return to your results list.</div>
        <div id="newSearchContainer"><asp:Button OnClick="DoNewSearch" Text="New Search" runat="server" CssClass="new_search_button_provider" ID="ProviderNewSearchButton"/></div>
        
        <script type="text/javascript">
        /*<![CDATA[*/
        if (document.getElementById)
        {
            // WI 33513 - Registration Type
            document.getElementById('backToResultsDiv').innerHTML 
                    = '<ul><li><input type="button" value="<%=this.backToResultsText %>" onclick="javascript:history.back(); return false;" /></li><li>' 
                        + document.getElementById('newSearchContainer').innerHTML + '</li></ul>';
            
            if(<%=searchMode %> == 0)
            {
                // We are in 'normal' provider search mode - so hide the "Back to Reg Results"
                document.getElementById('backToRegResultsDiv').innerHTML = '';
                document.getElementById('backToRegResultsDiv').style.display = 'none'; 
            }
            else
            {
                // In provider details page - but originally from a registration search
                // so we need to be able to return back to the registration list, as well
                // Add an extra "Back" button
                // as the provider one.
                document.getElementById('backToRegResultsDiv').innerHTML 
                    = '<ul><li><input type="button" value="<%=this.backToRegResultsText %>" onclick="javascript:history.go(-2); return false;" /></li><li>' 
                        + document.getElementById('backToResultsDiv').innerHTML + '</li></ul>';
                document.getElementById('backToResultsDiv').innerHTML = '';
                document.getElementById('backToResultsDiv').style.display = 'none'; 
            }
            document.getElementById('newSearchContainer').innerHTML = '';
            document.getElementById('newSearchContainer').style.display = 'none';
            // WI 33513 - Registration Type - End
            
            if(<%=nCookiesEnabled %> == 1)
            {
                document.getElementById('ManageBasketLink').innerHTML = 
                '<div class="results_basket_link"><a id="newAddProvLink" runat="server" href = "#" class="add_to_basket" onclick="AddProviderToBasket();return false;">'
                + '<%=this.addProviderToListText %></a><br /><br /><div class="added_to_basket" id="itemAddedId"></div></div>';
            }
            else
            {
                // Cookies aren't enabled
                document.getElementById('ManageBasketLink').innerHTML = '<a class="BasketCookieWarn"><%= this.cookieWarnText%><\/a>';
            }
        }
        /*]]>*/
        </script>
    </div>
    
    <div runat="server" id="ShoppingBasketContent" visible="false">         
         <!-- WI 42286 - Add Comparison Link -->
        <div><asp:Label ID="PrintHeaderText" runat="server"></asp:Label></div>
        <div id="compareHeaderTextDiv" runat="server" visible="false"><asp:Label ID="CompareHeaderText" runat="server" ></asp:Label></div>  
        
        <asp:Label ID="sbErrorMessage" CssClass="error_messages" runat="server"></asp:Label>
          
        <h2 id="shoppingBasketHeader" runat="server"></h2>
                
        <div id="printLinkDiv1" runat="server" class="provider_print_link"></div>        
        <!-- WI 42286 - Add Comparison Link -->     
        <div id="compareProvidersLink" class="compare_providers_link" runat="server" visible="false"></div>
        
		<asp:GridView ID="shoppingBasketProvidersGrid" runat="server" CssClass="shopping_basket_providers"></asp:GridView>
		
		<ul class="basket_links_ul">
			<li class="<%= this.shopbasket%>">
			    <asp:Button OnClick="clearBasketLink_Click" runat="server" id="clearBasketLink" />
			</li>
           	<li class="<%= this.shopbasket%>">
           	    <asp:Button OnClick="removeFromBasketLink_Click" runat="server" id="removeFromBasketLink" />
           	</li>
           	<li class="<%= this.shopbasket%>">
                <asp:Button OnClientClick="ReturnToResults(); return false;" runat="server" id="basketBackToResults" />
            </li>
             <li runat ="server" id="NewSearchLi">
	            <asp:Button OnClick="DoNewSearch" Text="New Search" runat="server" ID="BasketNewSearchButton"/>
	        </li>
		</ul>
               
        <div><input id="hiddenPageHistory" type="hidden" runat="server" /></div>
    
    </div>
    
</asp:Content>
